/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "ChrHairGeoDbc.h"

#include "GNativeFile.h"

namespace GNgine
{
	const std::string ChrHairGeoDbc::PATH="dbc/CharHairGeosets.dbc";

	ChrHairGeoDbc::ChrHairGeoDbc()
	{
		GFile* file=new GNativeFile(PATH);
		_dbc=new WOWDbcFile(file);
		delete file;
		assert(_dbc);
	}

	ChrHairGeoDbc& ChrHairGeoDbc::getSingleton()
	{
		static ChrHairGeoDbc inst;
		return inst;
	}
	
	ChrHairGeoDbc::RecordList ChrHairGeoDbc::getRecords(Ogre::uint race, Ogre::uint gender)
	{
		RecordList list;
		if(!_dbc){
			return list;
		}
		
		int cnt=_dbc->getRecordCount();
		for(int i=0;i<cnt;i++){
			int recordRace=_dbc->getUIntField(i,1);
			int recordGender=_dbc->getUIntField(i,2);

			if(recordRace==race&&recordGender==gender){
				CharHairGeoRecord *record=(CharHairGeoRecord*)_dbc->getRecordData(i);
				
				list.push_back(record);
			}
		}
		return list;
	}

	int ChrHairGeoDbc::getRecordCount(Ogre::uint race, Ogre::uint gender)
	{
		if(!_dbc){
			return 0;
		}
		int n=0;
		int cnt=_dbc->getRecordCount();
		for(int i=0;i<cnt;i++){
			int recordRace=_dbc->getUIntField(i,1);
			int recordGender=_dbc->getUIntField(i,2);

			if(recordRace==race&&recordGender==gender){
				n++;
			}
		}
		return n;
	}

	
}

